package cn.com.self.apis.controller;


import cn.com.self.apis.core.vo.ResultModel;
import cn.com.self.apis.portal.entity.DatatypeEntity;
import cn.com.self.apis.portal.entity.DatatypeGroupEntity;
import cn.com.self.apis.portal.service.intf.IDatatypeGroupService;
import cn.com.self.apis.portal.service.intf.IDatatypeService;
import cn.com.self.apis.portal.util.RedisUtils;
import cn.com.self.apis.portal.util.StringUtils;
import cn.com.selfsoft.smartcity.commons.Constants;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import cn.com.selfsoft.smartcity.commons.util.ParameterUtil;
import cn.com.selfsoft.smartcity.core.controller.GenericControllerImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author1 ssh
 * @author2
 * @date 2021-04-28
 */
@Controller
@Api(tags = "数据字典")
public class DataTypeAndGroupController  {


    @Autowired
    private IDatatypeGroupService datatypeGroupService;

    @Autowired
    private IDatatypeService datatypeService;



    /**
     * 根据字典类型或类型id获取字典详情
     *
     * @param
     * @param request
     * @return
     */
    @RequestMapping(value = {"/datatype/bygrouptypeOrID"}, method = RequestMethod.GET)
    @ApiOperation(value = "根据字典类型或类型id获取字典详情")
    public ResponseEntity Datatypes(Long groupId,String grouptype, HttpServletRequest request, Sort sort) {
        Map<String, Object> queryParams = ParameterUtil.HumpToUnderline(request.getParameterMap(),"access_token");
        List<DatatypeEntity> list=null;
        if(groupId !=null  || StringUtils.isNoneBlank(grouptype)){
            list=this.datatypeService.getListBygroupIdOrgrouptype(groupId,grouptype);
        }
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(list));

    }

    /**
     *
     * @param
     * @return
     */
    @RequestMapping(value = {"/datatype/init"}, method = RequestMethod.GET)
    @ApiOperation(value = "初始化字典缓存")
    public ResponseEntity initDatatypeRedis() {
        datatypeGroupService.initDatatypeRedis();
        return ResponseEntity.status(HttpStatus.OK).body(null);

    }




}

